import { request } from "@/utils/http";
import type { GetInfoResponse, LoginResponse } from "./model/userTypes";

// 登录
export const reqLogin = (username: string, password: string) => {
  // <any, string>的第一个类型为any即可，实际不会用上
  // 第二个类型是返回值数据中data的类型，根据接口文档填写
  return request.post<any, LoginResponse>("/admin/acl/index/login", {
    username,
    password,
  });
};

// 登出
export const reqLogout = () => {
  return request.post<any, null>("/admin/acl/index/logout");
};

// 查询用户信息
export const reqGetInfo = () => {
  return request.get<any, GetInfoResponse>("/admin/acl/index/info");
};


// 获取用户列表的接口
export const reqUserList = (page:any,limit:any,search:any) =>request.get<any,any>(`/admin/acl/user/${page}/${limit}`,{params:search})

// 添加新用户的接口
export const reqAddOrUpdateUser = (data:any) =>{
    if(data.id){
        request.put<any,any>('/admin/acl/user/update',data)
    }else{
        request.post<any,any>('/admin/acl/user/save',data)
    }
} 

// 批量删除的接口
export const reqBatchRemove =(ids:any)=>request.delete<any,any>('/admin/acl/user/batchRemove',ids)


// 根据用户获取角色数据
export const reqToAssign = (userId:any) => request.get<any,any>(`/admin/acl/user/toAssign/${userId}`)

// 给用户分配角色
export const reqDoAssign = (userId:any,roleId:any) => request.post<any,any>(`/admin/acl/user/doAssign?userId=${userId}&roleId=${roleId}`)

// 删除用户的接口
export const reqDeleteUser = (id:any) =>request.delete<any,any>(`/admin/acl/user/remove/${id}`)